﻿//// ===============================================================================
//// Project Name        :    Gfw.BLL.Basic.Stock.Facilities
//// Project Description :    
//// ===============================================================================
//// Class Name          :    BargainRecordFacility
//// Namespace:          :    Gfw.BLL.Basic.Stock.Facilities
//// Class Version       :    v1.0.0.0
//// Class Description   :    
//// CLR Version:        :    4.0.30319.17626
////Author               :    lif
//// Machine             :    ADICO-PC
//// Create Time         :    2012/7/14 16:58:59
//// Update Time         :    2012/7/14 16:58:59
//// ===============================================================================
//// Copyright © lif 2012 . All rights reserved.
//// ===============================================================================
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using Gfw.BLL.Basic.ExceptionImpl;
//using Gfw.BLL.Basic.Facilities;
//using Gfw.BLL.Basic.Stock.Enums;
//using Gfw.Models.Stock;
//using Gfw.Repositories.Stock;
//using Gfw.Repository;
//using Gfw.Stock.Base;

//namespace Gfw.BLL.Basic.Stock.Facilities
//{
//    /// <summary>
//    /// 股票交易记录功能，这里仅仅完成交易记录一张表
//    /// </summary>
//    public class BargainFacility:IFacility
//    {
//        private string _agencyId;
//        private double _count;
//        private double _price;


//        public BargainFacility(string agencyId,double price,
//                                     double count)
//        {
//            _price = price;
//            _count = count;
//            _agencyId = agencyId;
//        }

//        public void Execute(UnitOfWork unitOfWork = null)
//        {
//            if (unitOfWork == null)
//                throw new GfwTransactionInvalidException("功能事务作为原子操作是无效的。BargainRecordFacility");
//            BargainAgencyRepository agencyRep = new BargainAgencyRepository();
//            var agency = agencyRep.Get(_agencyId,unitOfWork);
//            if (agency.AgencyCount - agency.TradeCount< _count)
//                throw new GfwException("成交余额不足。");
//            var date = DateTime.Now;
//            agency.TradeDate = date;
//            agency.TradeCount += _count;
//            agency.TradePrice = _price;
//            agency.TradeStatus = agency.AgencyCount == 0 ? (int)TradeStatusEnum.Done : (int)TradeStatusEnum.PartDone;
//            agency.TradeTotal += _price*_count;

//            StkBargainrecord record = new StkBargainrecord()
//                                          {
//                                              Id = Guid.NewGuid().ToString(),
//                                              ActualCount = _count,
//                                              ActualPrice = _price,
//                                              AgencyCount = agency.AgencyCount,
//                                              AgencyId = agency.Id,
//                                              AgencyPrice = agency.AgencyPrice,
//                                              AwardSerialNo =
//                                                  agency.TradeType == (int) TradeTypeEnum.Sell
//                                                      ? Guid.NewGuid().ToString()
//                                                      : "",
//                                              BargainDate = date,
//                                              BargainType = agency.TradeType,
//                                              TotalPrice = _price*_count,
//                                              Userid = agency.Userid,
//                                              Income=0,
//                                              Taxation =0
//                                          };
//            //如果是卖出股票，则需要计算综合税费和个人所得，并启用动态奖金分配
//            if (record.BargainType == (int)TradeTypeEnum.Sell)
//            {
//                //调用动态奖金
//                record.Income = 0;
//                record.Taxation = 0;
//            }
//            BargainRecordRepository recordRep = new BargainRecordRepository();
//            recordRep.Save(record, unitOfWork);
//            agencyRep.Update(agency, unitOfWork);

//        }
//    }
//}
